<?php
	include_once 'BaseDAO.php';
	include_once '../object/Gallery.php';
	include_once '../util/Mapping.php';
	class Gallery_DAO extends BaseDAO
	{
		public function __construct(){

		}
                public function getList_Gallery($pro_id,$offset,$limit){

			$listGallery= array();
			$sql = "Select * from gallery where pro_id =".$pro_id." order by id ASC";
//		 	$sql .= " limit ".$offset.", ".$limit;
			$rs = parent::query($sql);
			while($row = $rs->fetch(PDO::FETCH_OBJ))
			{
				$gallery=new Gallery();
				Mapping::mapList_Gallery($row,$gallery);
				array_push($listGallery,$gallery);
			}
			return $listGallery;

		}
		public function getGallery_Detail($id)
		{

			$sql = "Select * from gallery where id=".$id;
			$rs = parent::query($sql);
			while($row = $rs->fetch(PDO::FETCH_OBJ))
			{
				$gallery=new Gallery();
				Mapping::mapList_Gallery($row,$gallery);
			}
			return $gallery;

		}
                public function getFirst_Gallery($id)
		{
			$sql = "Select * from gallery where pro_id=".$id." limit 0,1";
			$rs = parent::query($sql);
                        $image = "";
			$row = $rs->fetch(PDO::FETCH_OBJ);;
                        if(isset($row->gal_image))
                        $image = $row->gal_image;
			return $image;

		}
		public function getRows(){
			$sql = "select count(*) from Gallerys";
			$rs = parent::query($sql);
			$rows = $rs->fetch(PDO::FETCH_OBJ);
			return $rows;
		}
		public function insert_Gallery($image,$descript,$pro_id){
                        $sql = "INSERT INTO gallery(gal_image,gal_description,pro_id)
					 VALUES(
                                            '".$image."',
                                            '".addslashes($descript)."',
                                            '".$pro_id."')";
                        parent::execute($sql);
		}
		public function update_Gallery($id,$des)
		{
				$sql = "Update gallery set
                                        gal_description='".$des."'";
                                $sql .= "where pro_id='".$id."'";
			parent::execute($sql);			
		}
                public function delete_Gallery($id)
		{
			$sql = "Delete from gallery where id='".$id."'";
			parent::execute($sql);
		}
	}
?>